package oop.ex2.expression;

import oop.ex2.exceptions.UnrecognizedVariable;

/**
 * Implements the division operator.
 * @author daniel
 */
public class DivOpNode extends BinaryOpNode {

	/**
	 * Build a binary operator using the matched string.
	 * @param matchedString The matched string that generated this node.
	 */
	public DivOpNode(String matchedString) {
		super(matchedString);
	}

	@Override
	public double calculateNode() throws UnrecognizedVariable {
		//return the division of the two children
        double denom = _children.get(1).calculateNode();

        if (denom == 0)
            throw new ArithmeticException("Divide by zero error");
        
		return _children.get(0).calculateNode() / _children.get(1).calculateNode();
	}

}
